<!--
 * @Author: weidewei
 * @Date: 2025-11-19 15:16:21
 * @LastEditors: weidewei
 * @LastEditTime: 2025-11-19 15:26:21
 * @Description: 
 * @FilePath: \2025-front-face\html&css\瀑布流布局flex.html
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>瀑布流布局 - Flexbox实现</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }

      body {
        padding: 20px;
        background: #f5f5f5;
      }

      .waterfall {
        display: flex; /* ✅ 使用flex */
        gap: 20px; /* ✅ 列间距 */
      }

      .waterfall-column {
        flex: 1; 
        display: flex;
        flex-direction: column; /* ✅ 垂直排列 */
        gap: 20px; /* ✅ 项目间距 */
      }

      .waterfall-item {
        background: white;
        padding: 15px;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
      }

      /* 保持你的高度设置 */
      .item-1 {
        height: 200px;
        border: 1px solid red;
        background: #ffe0e0;
      }
      .item-2 {
        height: 300px;
        border: 1px solid red;
        background: #e0ffe0;
      }
      .item-3 {
        height: 250px;
        border: 1px solid red;
        background: #e0e0ff;
      }
      .item-4 {
        height: 180px;
        border: 1px solid red;
        background: #ffffe0;
      }
      .item-5 {
        height: 320px;
        border: 1px solid red;
        background: #e0ffff;
      }
      .item-6 {
        height: 220px;
        border: 1px solid red;
        background: #f0e0ff;
      }
      .item-7 {
        height: 280px;
        border: 1px solid red;
        background: #ffe0f0;
      }
      .item-8 {
        height: 190px;
        border: 1px solid red;
        background: #f0ffe0;
      }
    </style>
  </head>
  <body>
    <h2>瀑布流布局 - Flexbox实现（需要手动分列）</h2>

    <div class="waterfall">
      <!-- 左列 -->
      <div class="waterfall-column">
        <div class="item-1 waterfall-item">1</div>
        <div class="item-4 waterfall-item">4</div>
        <div class="item-7 waterfall-item">7</div>
      </div>

      <!-- 中列 -->
      <div class="waterfall-column">
        <div class="item-2 waterfall-item">2</div>
        <div class="item-5 waterfall-item">5</div>
        <div class="item-8 waterfall-item">8</div>
      </div>

      <!-- 右列 -->
      <div class="waterfall-column">
        <div class="item-3 waterfall-item">3</div>
        <div class="item-6 waterfall-item">6</div>
      </div>
    </div>
  </body>
</html>
